<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_addfile"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        .input-group {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_addfile"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <input type="file" id="file" name="file" style="margin-left: 50px">
            </div>
        </div>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_overlay" onclick="add()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_addToLater" onclick="addtolayer()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_open" onclick="openfile()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearlayer()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,fileupLoad,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, local, layer, vectorLayer, control, queryBounds, markerLayer, drawFeature;
    var plottingLayer, plottingEdit, sitManager, ListFile, plotting;
    var host = window.isLocal ? window.server : "http://iclsvr.supermap.io";
    var mapurl = host + "/iserver/services/map-china400/rest/maps/China_4326";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});


        plottingLayer = new SuperMap.Layer.PlottingLayer("标绘图层", serverUrl);
        plottingLayer.style = {
            fillColor: "#66cccc",
            fillOpacity: 0.4,
            strokeColor: "#66cccc",
            strokeOpacity: 1,
            strokeWidth: 3,
            pointRadius: 6
        };

        //态势标绘编辑
        plottingEdit = new SuperMap.Control.PlottingEdit();
        //添加态势标绘控件
        map.addControls([plottingEdit]);

        plotting = SuperMap.Plotting.getInstance(map, serverUrl);
        sitManager = plotting.getSitDataManager();
        sitManager.events.on({
            "addSmlFileCompleted": success,
            "addSmlFileFailed": fail,
            "addSmlFileToLayerCompleted": success,
            "addSmlFileToLayerFailed": fail,
            "openSmlFileCompleted": openSuccess,
            "openSmlFileFailed": fail
        });
    }

    function addLayer() {
        map.addLayers([layer, plottingLayer]);
        map.setCenter(new SuperMap.LonLat(104, 35), 3);
        fileFilter();
        plottingEdit.activate();
    }

    function add() {
        widgets.alert.clearAlert();
        sitManager.addSmlFile('file', true);
    }

    function addtolayer() {
        widgets.alert.clearAlert();
        sitManager.addSmlFileToLayer('file', "标绘图层");

    }

    function openfile() {
        widgets.alert.clearAlert();
        sitManager.openSmlFile('file');
    }

    function clearlayer() {
        widgets.alert.clearAlert();
        plottingEdit.deactivate();

        var layers = map.layers;
        for (var n = 0; n < layers.length; n++) {
            if (layers[n].isEditable) {
                layers[n].removeAllFeatures();
            }
        }
    }

    function fileFilter() {
        var file = document.getElementById('file');
        file.setAttribute("accept", ".sml");
    }

    function success() {

    }

    function openSuccess() {
        var sitDataLayers = sitManager.getSitDataLayers();
        plottingLayer = sitDataLayers[0];
    }

    function fail() {
        widgets.alert.showAlert(resources.msg_overlayFailed, false);
    }

</script>

</body>
</html>